<template>
  <div class="content">
    <file-list v-if="securePwd_not_existence" format="private" />
  </div>
</template>
<script>
import file_list from '../file_list'
import { inputDialog, success, error } from '@/util/message'
import { setSecurePassword, checkSecurePassword } from '@/api/requests/user'
export default {
  components: {
    'file-list': file_list
  },
  data () {
    return {
      securePwd_not_existence: false
    }
  },
  created () {
    this.private_Auth()
  },
  methods: {
    private_Auth () {
      this.securePwd_not_existence = false
      let that = this
      if (this.$auth('securePwd.existence') == false) {
        inputDialog(that, '创建安全密码', '请你创建一个安全密码，创建后不允许修改', (value) => {
          setSecurePassword(value).then(res => {
            if (res.code == 200) {
              success(that, '创建成功')
              router.go(0)
            }
          })
        }, () => {
          window.location.href = '/#/pan/all_file'

        })
      } else {
        inputDialog(that, '输入安全密码', '请你输入你的安全密码', (value) => {
          checkSecurePassword(value).then(res => {
            if (res.code == 200) {
              success(that, '校验成功')
              this.securePwd_not_existence = true

            } else {
              error(that, '校验失败')
              setTimeout(() => {
                window.location.href = '/#/pan/all_file'
              }, 500);
            }
          })
        }, () => {
          window.location.href = '/#/pan/all_file'
        })
      }
    }
  },

}
</script>